/**
 * 
 */
package com.googlecode.xcarve.serilize.test;

import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.sql.Timestamp;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import com.googlecode.xcarve.coder.hessian.Hessian2Output;

/**
 * @author xinyun.d
 * 2015年1月11日
 */
public class HessianVsJson {
	
	public static void main(String[] args) {
		System.gc();
		Person p = new Person();
		p.setAge(12);
		p.setCount(21L);
		p.setCreateTime(new Timestamp(System.currentTimeMillis()));
		p.setDate(new Date());
		p.setFlags(false);
		p.setId(1);
		p.setName("hello");
		p.setStatus((byte)1);
		
		
//		encodeAndDecode(p);
	}

	public static void encodeAndDecode(Person p){
		
		try {
			List<Person> list = new ArrayList<Person>();
			for(int i=0;i<1000;i++){
				list.add(p);
			}
			long start = System.currentTimeMillis() ;
			ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
			Hessian2Output out = new Hessian2Output(byteArrayOutputStream);
			out.writeObject(list);
			out.flushBuffer();
			long end = System.currentTimeMillis() ;
			System.out.println((end-start));
			
 
//			System.out.println("hessian len:"+byteArrayOutputStream.toByteArray().length);
//			ByteBuffer buffer = ByteBuffer.allocateDirect(byteArrayOutputStream.toByteArray().length);
//			System.out.println(byteArrayOutputStream.size());
//			System.out.println(buffer.limit());
//			System.out.println(buffer.capacity());
		} catch (IOException e) {
			e.printStackTrace();
		}
		
//		ByteArrayInputStream byteInput = new ByteArrayInputStream(byteArrayOutputStream.toByteArray());
//		HessianInputObject encode = new HessianInputObject(byteInput);
//		try {
//			RequestMessage result = (RequestMessage)encode.readObject(RequestMessage.class);
//			System.out.println(msg);
//			System.out.println(result);
//		} catch (IOException e) {
//			e.printStackTrace();
//		}
		
	}
	
 
}
